package com.think.admin.config;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.think.common.enums.IsDeleteEnum;
import com.think.common.enums.StateEnum;
import org.apache.ibatis.reflection.MetaObject;

import java.time.LocalDateTime;

/**
 * <p>
 * web plus：admin自动填充类
 * </p>
 *
 * @author: xwj
 * @data: 2019-04-07
 */
public class AdminMetaObjectHandler implements MetaObjectHandler {
    /**
     * 修改时间
     */
    private final String gmtModified = "gmtModified";
    private final String updateTime = "updateTime";
    private final String createTime = "createTime";

    @Override
    public void insertFill(MetaObject metaObject) {
        setInsertFieldValByName("gmtCreate", LocalDateTime.now(), metaObject);
        setInsertFieldValByName(gmtModified, LocalDateTime.now(), metaObject);
        setInsertFieldValByName("state", StateEnum.ENABLE, metaObject);
        setInsertFieldValByName("isDelete", IsDeleteEnum.NORMAL, metaObject);
        setInsertFieldValByName(updateTime, LocalDateTime.now(), metaObject);
        setInsertFieldValByName(createTime, LocalDateTime.now(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        setInsertFieldValByName(gmtModified, LocalDateTime.now(), metaObject);
        setInsertFieldValByName(updateTime, LocalDateTime.now(), metaObject);
    }
}
